package cn.hxth.cloud.provider.updater;


import cn.hxth.cloud.api.common.util.DateProvider;
import cn.hxth.cloud.api.domain.Steels;
import cn.hxth.cloud.api.domain.SteelsInputOrder;
import cn.hxth.cloud.api.domain.SteelsInputOrderItem;
import cn.hxth.cloud.api.mapper.SteelsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class InPutSteelsUpdaterFactory extends AbstractSteelsUpdaterFactory<SteelsInputOrder> {

  @Autowired
    public InPutSteelsUpdaterFactory(DateProvider dateProvider, SteelsMapper steelsMapper) {
        super(dateProvider, steelsMapper);
    }

    @Override
    protected List<Long> getSteelsIds(SteelsInputOrder parameter) throws Exception {
        List<SteelsInputOrderItem> steelsInputOrderItems = parameter.getSteelsInputOrderItems();
        List<Long> ids = new ArrayList<>(steelsInputOrderItems.size()) ;
        for(SteelsInputOrderItem steelsInputOrderItem:steelsInputOrderItems){
            Long id = steelsInputOrderItem.getSid();
            ids.add(id) ;

        }
        return ids;
    }

    @Override
    protected SteelsUpdater createSteelsUpdater(List<Steels> steels, SteelsInputOrder parameter) throws Exception {
        Map<Long,SteelsInputOrderItem> map = new HashMap<>() ;
        for(SteelsInputOrderItem steelsInputOrderItem:parameter.getSteelsInputOrderItems()){
            map.put(steelsInputOrderItem.getSid(),steelsInputOrderItem) ;
        }
        return new InPutSteelsUpdater(steels,steelsMapper,dateProvider,map) ;
    }



}

